package fr.noe.amicaleloisirs.concours.business;

import fr.noe.amicaleloisirs.concours.utils.Constants;
import fr.noe.amicaleloisirs.concours.utils.Logger;

public class Match {

	private Team t1;
	private Team t2;

	public Match(Team t1, Team t2) {
		this.t1 = t1;
		this.t2 = t2;
		if (t1 != null && t2 != null) {
			t1.addEquipeRencontree(t2.getTeamId());
			t2.addEquipeRencontree(t1.getTeamId());
		}
	}

	public Team getT1() {
		return t1;
	}

	public Team getT2() {
		return t2;
	}
	
	public void setT1(Team t1) {
		if (this.t1 == null)
			this.t1 = t1;
	}

	public void setT2(Team t2) {
		if (this.t2 == null)
			this.t2 = t2;
	}

	public void setMatchResult(int pointsT1, int pointsT2) {
		if (t1 == null) {
			t2.setAlreadyExempt(true);
			t2.setResultat(Constants.NB_POINT_VICTOIRE_DEFAUT, Constants.NB_POINT_DEFAITE_DEFAUT);
		}
		else if (t2 == null) {
			t1.setAlreadyExempt(true);
			t1.setResultat(Constants.NB_POINT_VICTOIRE_DEFAUT, Constants.NB_POINT_DEFAITE_DEFAUT);
		}
		else {
			t1.setResultat(pointsT1, pointsT2);
			t2.setResultat(pointsT2, pointsT1);
		}
	}
	
	public boolean isMatchWithTwoTeams() {
		return (t1 != null) && (t2 != null);
	}
	
	private static void log(String text) {
		Logger.get().logWithClass("Match", text);
	}
}
